﻿'
' Will Strohl (will.strohl@gmail.com)
' http://www.willstrohl.com
'
'Copyright (c) 2011, Will Strohl
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without modification, are 
'permitted provided that the following conditions are met:
'
'Redistributions of source code must retain the above copyright notice, this list of 
'conditions and the following disclaimer.
'
'Redistributions in binary form must reproduce the above copyright notice, this list 
'of conditions and the following disclaimer in the documentation and/or other 
'materials provided with the distribution.
'
'Neither the name of Will Strohl nor the names of its contributors may be 
'used to endorse or promote products derived from this software without specific prior 
'written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
'EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
'SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
'TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
'BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
'CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
'ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 
'DAMAGE.
'

Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions

Namespace WillStrohl.Modules.CodeCamp

    Partial Public MustInherit Class Speakers
        Inherits WNSPortalModuleBase
        Implements IActionable

#Region " Private Members "

        Private Const c_ActionMenuItem As String = "MenuItem.Edit"

        Private p_CodeCampId As Integer = Null.NullInteger
        Private p_CodeCamp As CodeCampInfo = Nothing
        Private p_SettingsUrl As String = String.Empty
        Private p_SpeakerCount As String = String.Empty
        Private p_SessionCount As String = String.Empty

#End Region

#Region " Private Properties "

        Private ReadOnly Property CodeCampId As Integer
            Get
                If Me.p_CodeCampId = Null.NullInteger And Not Me.Settings("CodeCampId") Is Nothing Then
                    Integer.TryParse(Me.Settings("CodeCampId").ToString, Me.p_CodeCampId)
                End If

                Return Me.p_CodeCampId
            End Get
        End Property

        Private ReadOnly Property CodeCamp As CodeCampInfo
            Get
                If Me.p_CodeCamp Is Nothing And Me.CodeCampId > 0 Then
                    Dim ctlCodeCamp As New CodeCampController
                    Me.p_CodeCamp = ctlCodeCamp.GetCodeCampById(Me.CodeCampId)
                End If

                Return Me.p_CodeCamp
            End Get
        End Property

        Private ReadOnly Property SettingsUrl As String
            Get
                If String.IsNullOrEmpty(Me.p_SettingsUrl) Then
                    Me.p_SettingsUrl = Me.EditUrl(String.Empty, String.Empty, "Edit")
                End If

                Return Me.p_SettingsUrl
            End Get
        End Property

        Protected ReadOnly Property SpeakerCount As String
            Get
                If String.IsNullOrEmpty(Me.p_SpeakerCount) Then
                    Dim ctlModule As New CodeCampController
                    Me.p_SpeakerCount = ctlModule.CodeCampSpeakerCount(Me.CodeCampId).ToString
                End If

                Return Me.p_SpeakerCount
            End Get
        End Property

        Protected ReadOnly Property SessionCount As String
            Get
                If String.IsNullOrEmpty(Me.p_SessionCount) Then
                    Dim ctlModule As New CodeCampController
                    Me.p_SessionCount = ctlModule.CodeCampSessionCount(Me.CodeCampId).ToString
                End If

                Return Me.p_SessionCount
            End Get
        End Property

#End Region

#Region " Event Handlers "

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try

                ' request that the DNN framework load the jQuery script into the markup
                DotNetNuke.Framework.jQuery.RequestRegistration()

                Me.BindData()

            Catch exc As Exception ' Module failed to load
                ProcessModuleLoadException(Me, exc, Me.IsEditable)
            End Try
        End Sub

#End Region

#Region " Helper Methods "

        Private Sub BindData()

            Me.LocalizeModule()
            
            Me.pnlNoCodeCamp.Visible = (Me.CodeCamp Is Nothing)

            If Not Me.pnlNoCodeCamp.Visible Then

                Dim ctlCodeCamp As New CodeCampController

                Me.pnlNoSpeakers.Visible = (ctlCodeCamp.CodeCampSpeakerCount(Me.CodeCamp.CodeCampId) > 0)

                Me.pnlSpeakers.Visible = Not Me.pnlNoSpeakers.Visible
                Me.pnlStatus.Visible = (Not Me.pnlNoSpeakers.Visible And Me.IsEditable)

                If Me.IsEditable Then
                    Me.rptSpeakers.DataSource = ctlCodeCamp.GetSpeakersByCodeCampAll(Me.CodeCampId)
                Else
                    Me.rptSpeakers.DataSource = ctlCodeCamp.GetSpeakersByCodeCamp(Me.CodeCampId)
                End If
                Me.rptSpeakers.DataBind()

            End If

        End Sub

        Private Sub LocalizeModule()



        End Sub

#End Region

#Region " IActionable Implementation "

        Public ReadOnly Property ModuleActions() As DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Implements IActionable.ModuleActions
            Get
                Dim Actions As New Actions.ModuleActionCollection
                Actions.Add(GetNextActionID, Me.GetLocalizedString(c_ActionMenuItem), _
                    String.Empty, String.Empty, String.Empty, _
                    Me.SettingsUrl, _
                    False, DotNetNuke.Security.SecurityAccessLevel.Edit, True, False)
                Return Actions
            End Get
        End Property

#End Region

    End Class

End Namespace